package org.crumbleworks.crumbcrane.crate.armed;

import org.crumbleworks.crumbcrane.crate.ArmedCrate;
import org.crumbleworks.crumbcrane.crate.Crate;
import org.newdawn.slick.opengl.Texture;

public abstract class ExplosiveCrate extends ArmedCrate {
    protected int damageThreshold;

    public ExplosiveCrate(float x, float y, float width, float height, float r, float g, float b, Texture texture, int hitPoints, int damageResistance, int damagePoints, int range) {
        super(x, y, width, height, r, g, b, texture, hitPoints, damageResistance, damagePoints, range);
    }
    
    /**
     * Implementation for ExplosiveCrate.
     * 
     * @param attackedCrate crate which is about to be attacked
     * @return true if attacked crate is destroyed, else false
     */
    @Override
    public boolean attack(Crate attackedCrate) {
        int tempHitPoints = attackedCrate.getHitPoints() - (damagePoints - attackedCrate.getDamageResistance());

        if(tempHitPoints > 0) {
            attackedCrate.setHitPoints(tempHitPoints);
            return false;
        }
        
        attackedCrate.setHitPoints(0);
        return true;
    }
    
    public int getDamageThreshold() {
        return damageThreshold;
    }

    public void setDamageThreshold(int damageThreshold) {
        this.damageThreshold = damageThreshold;
    }
}
